<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
$intLID = (int)$_data["LID"];

/*$arrUser = getUserDataArrayByID($intID);
if($arrUser === false){
	ErrMsgOutputHTML("Error", "", 1);
}
if(sizeof($arrUser) == 0){
	header("Location: ".basename($_SERVER["PHP_SELF"])."?op=List");
	exit();
}*/

//取出使用者是否自動補貨設定  定義在 bet_MemberLimit 裡 LID => 0, BT => 1, LimitType => 3
$intPreIsAutoSupple = getUserIsAutoSupple($intID);
if($intPreIsAutoSupple === false)ErrMsgOutputHTML("Error", "", 1);

if(empty($intLID)){
	$intLID = (defined('__MemInitLottoID'))?__MemInitLottoID:1;
	if(empty($intLID))$intLID = 1;
}
include_once(__Common_Path."/betparam/BetParam_".$intLID.".inc.php");

$arrLimits = getUserLimitsArray($intID, $intLID);
if($arrLimits === false)ErrMsgOutputHTML("Error", "", 1);

$arrLotto = $_arrLotto[$intLID];

$fp = @file($strTemplatePath."CommParams.html");
$fp = implode("", $fp);
$fp = setHTMLCharset($fp);
$fp = str_replace("{intID}", $intID, $fp);

$fp = str_replace("{ShowAccount}", $_SESSION["Admin_Info"] -> Account, $fp);
$fp = str_replace("{ShowName}", $_SESSION["Admin_Info"] -> Name, $fp);
//$fp = str_replace("{ShowAddDate}", $arrUser["AddDate"], $fp);
$fp = str_replace("{ShowLID}", $intLID, $fp);
$fp = str_replace("{IsAutoDisabled}", ($intPreIsAutoSupple == 1?"checked":""), $fp);
//$fp = str_replace("{IsAutoDisabled}", "checked", $fp);

$strLIDOption = "";
foreach($_arrLotto as $intLottoID => $arrLottoData){
	//if($intLottoID != 1)continue;
	$strSelect = ($intLottoID == $intLID)?" selected":"";
	$strLIDOption .= "<option value='".$intLottoID."'".$strSelect.">".$arrLottoData["Lotto_".$_intLang]."</option>\n";
}
$fp = str_replace("{ShowLID_Options}", $strLIDOption, $fp);

while(list($k, $v) = each($_strAutoSuppleSetting)){
	$fp = str_replace("{".$k."}", $v, $fp);
}


preg_match("/<!-- @ Content Start @ \/\/-->(.+)<!-- @ Content End @ \/\/-->/s", $fp, $arrCon);
preg_match("/<!-- @ BTTitle Start @ \/\/-->(.+)<!-- @ BTTitle End @ \/\/-->/s", $arrCon[1], $arrBTTitle); //下注種類 Title
preg_match("/<!-- @ IsOpen Start @ \/\/-->(.+)<!-- @ IsOpen End @ \/\/-->/s", $arrCon[1], $arrIsOpen); //是否開放
preg_match("/<!-- @ LimitGold Start @ \/\/-->(.+)<!-- @ LimitGold End @ \/\/-->/s", $arrCon[1], $arrLimitGold); //實貨限額

$arrTemplate["Table"] = $arrCon[1];
$arrTemplate["BTTitle"] = $arrBTTitle[1];
$arrTemplate["IsOpen"] = $arrIsOpen[1];
$arrTemplate["LimitGold"] = $arrLimitGold[1];

$intRows = ceil(sizeof($_arrBet_Type[$arrLotto["LType"]]) / 10);
list($intFirstBT) = each($_arrBet_Type[$arrLotto["LType"]]);
$intFirstBT -= 1;

$intCol = 0;
$arrBTTitle = array();
$arrIsOpen = array();
$arrLimitGold = array();
$strTmpTable = array();
$arrBT = $_arrBet_Type[$arrLotto["LType"]];
foreach($arrBT as $intBT => $strBT){
	if($intLID == 1 && $intBT == 28)continue;
	if($intLID == 1 && $intBT == 1)$strBT .= "B";

	$isAutoSupple = $_arrBetParam[$intBT][0]["isAutoSupple"];
	

	$strBTTitle = str_replace("{BTTitle}", $strBT, $arrTemplate["BTTitle"]);
	$strLimitGold = str_replace("{ShowLimitGold}", ($arrLimits[3][$intBT] === null?-1:$arrLimits[3][$intBT]), $arrTemplate["LimitGold"]);
	$strLimitGold = str_replace("{BT}", $intBT, $strLimitGold);

	if($isAutoSupple){	//是否開放自動補貨
		$strIsOpen = str_replace("{ShowIsOpen}", $_strAutoSuppleSetting["Yes"], $arrTemplate["IsOpen"]);
		$strLimitGold = str_replace("{disabled}", "", $strLimitGold);
	}else{
		$strIsOpen = str_replace("{ShowIsOpen}", $_strAutoSuppleSetting["No"], $arrTemplate["IsOpen"]);
		$strLimitGold = str_replace("{disabled}", "disabled", $strLimitGold);
	}
	$arrBTTitle[] = $strBTTitle;
	$arrIsOpen[] = $strIsOpen;
	$arrLimitGold[] = $strLimitGold;

	if(sizeof($arrBTTitle) == 10){
		$strTmpTable = $arrTemplate["Table"];
		$strBTTitle = implode("", $arrBTTitle);
		$strIsOpen = implode("", $arrIsOpen);
		$strLimitGold = implode("", $arrLimitGold);

		$strTmpTable = preg_replace("/<!-- @ BTTitle Start @ \/\/-->.+<!-- @ BTTitle End @ \/\/-->/s", $strBTTitle, $strTmpTable);
		$strTmpTable = preg_replace("/<!-- @ IsOpen Start @ \/\/-->.+<!-- @ IsOpen End @ \/\/-->/s", $strIsOpen, $strTmpTable);
		$strTmpTable = preg_replace("/<!-- @ LimitGold Start @ \/\/-->.+<!-- @ LimitGold End @ \/\/-->/s", $strLimitGold, $strTmpTable);

		$strTmpTable = str_replace("{ShowColspan}", "colspan='10'", $strTmpTable);
		$arrTmpTable[] = $strTmpTable;

		$arrBTTitle = array();
		$arrIsOpen = array();
		$arrLimitGold = array();
	}
}

if(sizeof($arrBTTitle) > 0){
	$strTmpTable = $arrTemplate["Table"];
	$strBTTitle = implode("", $arrBTTitle);
	$strIsOpen = implode("", $arrIsOpen);
	$strLimitGold = implode("", $arrLimitGold);

	$strTmpTable = preg_replace("/<!-- @ BTTitle Start @ \/\/-->.+<!-- @ BTTitle End @ \/\/-->/s", $strBTTitle, $strTmpTable);
	$strTmpTable = preg_replace("/<!-- @ IsOpen Start @ \/\/-->.+<!-- @ IsOpen End @ \/\/-->/s", $strIsOpen, $strTmpTable);
	$strTmpTable = preg_replace("/<!-- @ LimitGold Start @ \/\/-->.+<!-- @ LimitGold End @ \/\/-->/s", $strLimitGold, $strTmpTable);

	$strTmpTable = str_replace("{ShowColspan}", "colspan='".(sizeof($arrBTTitle))."'", $strTmpTable);
	$arrTmpTable[] = $strTmpTable;
}
$strTmp = "";
if(sizeof($arrTmpTable) > 0)$strTmp = implode("\n", $arrTmpTable);

$fp = preg_replace("/<!-- @ Content Start @ \/\/-->.+<!-- @ Content End @ \/\/-->/s", $strTmp, $fp);


//輸出
WebOutputHTML($fp, 1);
?>